﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace LunarSF.SHomeWorkshop.LunarMarkdownEditor
{
    public class MarkdownFileInfo
    {
        public MarkdownFileInfo(string fullPath, string tailPath)
        {
            FullPath = fullPath;
            TailPath = tailPath;
        }

        public string FullPath { get; } = "";

        public string TailPath { get; } = "";
    }

    public class MarkdownFile
    {
        public MarkdownFile(string title, string path)
        {
            this.Title = title.Replace("<","&lt;").Replace(">","&gt;").Replace("&","&amp;");
            this.FullPath = path;
        }
        public string FullPath { get; set; }
        public string Title { get; set; }
        /// <summary>
        /// 返回文件短名。
        /// </summary>
        public string Name
        {
            get
            {
                try
                {
                    return new FileInfo(this.FullPath).Name;
                }
                catch { return null; }
            }
        }
        /// <summary>
        /// 无文件后缀名的知名称。
        /// </summary>
        public string CleanName
        {
            get
            {
                var name = Name;
                if (string.IsNullOrEmpty(name) == false)
                {
                    var lastIndexOfDot = name.LastIndexOf('.');
                    if (lastIndexOfDot >= 0)
                    {
                        return name.Substring(0, lastIndexOfDot);
                    }
                    else return name;
                }
                return name;
            }
        }

        /// <summary>
        /// 用于导出 Epub 文件时临时使用的路径。
        /// </summary>
        internal string EpubTempPath { get; set; }
    }
}
